package com.zking.service.impl;

import com.zking.entity.ProductOne;
import com.zking.entity.ProductTwo;
import com.zking.mapper.ProductOneMapper;
import com.zking.mapper.ProductTwoMapper;
import com.zking.service.FenleiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class FenleiServiceImpl extends BaseServiceImpl<ProductOne> implements FenleiService {

    @Autowired
    ProductOneMapper oneMapper;
    @Autowired
    ProductTwoMapper twoMapper;


    @Transactional(readOnly = true)
    public List<ProductOne> findOneAndTwo() {
        // 查询到所有一级
        List<ProductOne> ones = oneMapper.selectAll();
        for (ProductOne one : ones) {
            // 二级分类数据查询
            ProductTwo two = new ProductTwo();
            two.setParentid(one.getId());
            List<ProductTwo> twos = twoMapper.select(two);
            one.setTwos(twos);
        }
        return ones;
    }
}
